var QueryPurchaseAndOrdesdetail = new Vue({
    el: '#QueryPurchaseAndOrdesdetail',
    //初始化数据类型
    data: {
        code: '待审核',
        activeName: 'PendingReview',
        TimeRange: [],
        sizeForm: {
            companyname: '',
            entryname: '',
            startTime: '',
            endTime: '',
            type: '',
            commodityName: '',
            radio5: ''
        },
        tableData3: [],
        dialogFormVisible: false,
        dialogVisible: false,
        form: {
            good_score: '',
            service_score: '',
            content: '',
            order_id: '',
            commodity_id: '',
            merchantid: '',
            ordersid: '',
            orderslistid: '',
            orderId: '',
            commodityId: ''
        },
        formLabelWidth: '120px'
    },
    //时间提交方法
    methods: {

        handleClick: function (tab, event) {
            debugger
            var _this = this;
            _this.cond = tab.label;
            $.post("/home/purchase_orders/queryAllDatas",
                {"cond": _this.cond, "goodsName": '', "GMFS": '', "entryName": '', "contact": ''},
                function (data) {
                    _this.dataCombination(data.data.queryAllData4PurchaseVoList);
                });
            console.log(tab, event);
        },

        //时间格式化
        dateFormat: function (row, column) {
            var date = row[column.property];
            if (date == undefined) {
                return "";
            }
            return moment(date).format("YYYY-MM-DD");
        },
        onSubmit: function () {
            var _this = this;
            $.post("/home/purchase_orders/queryAllDatas",
                {
                    "cond": _this.cond,
                    "goodsName": _this.sizeForm.commodityName,
                    "GMFS": _this.sizeForm.radio5,
                    "entryName": _this.sizeForm.entryname,
                    "contact": _this.sizeForm.companyname
                },
                function (data) {
                    _this.dataCombination(data.data.queryAllData4PurchaseVoList);
                });

        },

        dialogFormVisibleClick: function (row) {
            var _this = this;

            _this.form.merchantid = row.merchantid;
            _this.form.ordersid = row.ordersid;
            _this.form.orderslistid = row.orderslistid;
            _this.form.orderId = row.orderslistid;
            _this.form.commodityId = row.commodityId;
            _this.dialogFormVisible = true;
        },
        dialogFormVisibleEnter: function () {
            var _this = this;
            if (_this.form.commodityId != 0) {
                $.post("/home/estimate/insertShop",
                    {"sizeForm": JSON.stringify(_this.form)},
                    function (data) {
                        if (data.code == 200) {
                            if (data.data.flag == "true") {
                                _this.$notify({
                                    message: "评价成功",
                                    type: 'success'
                                });
                            }
                            _this.initForms();
                        } else {
                            _this.$notify({
                                message: "评价失败，请重新评价",
                                type: 'error'
                            });
                            _this.initForms();
                        }
                    });
            } else {
                _this.$notify({
                    message: "评价失败，该产品属于手工添加类产品，无法评价。",
                    type: 'error'
                });
                _this.initForms();
            }
            _this.dialogFormVisible = false;
        },
        initForms: function () {
            var _this = this;
            _this.form.good_score = '';
            _this.form.service_score = '';
            _this.form.content = '';
            _this.form.order_id = '';
            _this.form.commodity_id = '';
            _this.form.merchantid = '';
            _this.form.ordersid = '';
            _this.form.orderslistid = '';
            _this.form.orderId = '';
            _this.form.commodityId = '';
        },
        queryPurchase: function (rowIndex, row) {
            var _this = this;
            //查询主单关联清单情况
            $.post("/home/purchase_orders/selectOrdersAllById",
                {"ordersId": row.ordersid},
                function (data) {
                    if (data.code == 200) {
                        $("#wrap-left").load("http://" + window.location.host + "/home/PurchaseAndOrdesdetail.html", function () {
                            PurchaseAndOrdesdetail.urchaseAndOrdersdetail = data.data.purchaseOrders;
                            PurchaseAndOrdesdetail.ordersDetails = data.data.purchaseDetailedList;
                            PurchaseAndOrdesdetail.urchaseAndOrdersdetail.ifInput = true;
                            PurchaseAndOrdesdetail.urchaseAndOrdersdetail.queryFlag = true;
                        });
                    } else {
                        _this.$notify({
                            message: "采购单查询失败。",
                            type: 'error'
                        });
                        return;
                    }
                });

        },
        queryList: function (rowIndex, row) {
            debugger
            var _this = this;
            if (row.gmfs == '二次询价') {
                $.post("/home/quotation/selectListQuoteById",
                    {"id": row.quotationid},
                    function (data) {
                        if (data.code == 200) {

                            $("#wrap-left").load( "/home/quotation.html", function () {
                                debugger
                                quotation.quoteOrCompare = data.data.QuotationList[0];
                                quotation.quoteOrCompare.ifQuery = false;
                                $(".hmtop").css("display","none");
                            });
                        } else {
                            _this.$notify({
                                message: "报价单查询失败。",
                                type: 'error'
                            });
                            return;
                        }
                    });
            } else {
                _this.$notify({
                    message: "对不起，直接购买商品没有对应的报价单。",
                    type: 'error'
                });
                return;
            }
            $(".line").hide();
        },

        Edit2: function (rowIndex, row) {
            var _this = this;
            if (row.type == '等待确认单' || row.type === '审核通过' || row.type === '结果确认' || row.type === '待完成' || row.type === '已完成') {
                $.post("/home/purchase_orders/selectOrdersAllById",
                    {"ordersId": row.ordersid},
                    function (data) {
                        if (data.code == 200) {
                            $("#wrap-left").load("http://" + window.location.host + "/home/PurchaseAndOrdesdetailResultValidation.html", function () {
                                purchaseAndOrdersdetailResultVaidation.urchaseAndOrdersdetail = data.data.purchaseOrders;
                            });
                        } else {
                            _this.$notify({
                                message: "对不起，没有查询到对应的确认通知书。",
                                type: 'error'
                            });
                            return;
                        }
                    });
            } else {
                _this.$notify({
                    message: "对不起，该订单还不可以生成对应的确认通知书。",
                    type: 'error'
                });
                return;
            }
        },

        printPurchase: function (rowIndex, row) {
            var _this = this;
            if (row.type != '申请' && row.type != '待审核') {
                debugger
                row.ordersid;
                $.post("/home/purchase_orders/selectOrdersById4Excel",
                    {"ordersId": row.ordersid},
                    function (data) {
                        //跳转添加采购单清单
                        $("#wrap-left").load("http://" + window.location.host + "/home/PurchaseExcel.html", function () {
                            PurchaseExcel.urchaseAndOrdersdetail = data.data.purchaseOrders;
                        });

                    });
            } else {
                _this.$notify({
                    message: '请注意，该订单还没有被审核，无法打印审核单！',
                    type: 'error'
                });
                return;
            }
        },
        printPurchaseList: function (rowIndex, row) {
            var _this = this;
            if (row.type != '申请' && row.type != '待审核') {
                $.post("/home/purchase_orders/selectPurchaseDetailedListAllByOrdersId",
                    {"ordersId": row.ordersid},
                    function (data) {
                        $("#wrap-left").load("http://" + window.location.host + "/home/PurchaseExcelList.html", function () {
                            PurchaseExcelList.ordersDetails = data.data.purchaseDetailedList;
                            PurchaseExcelList.cgdw = row.company_name;
                        });
                    });
            } else {
                _this.$notify({
                    message: '请注意，该订单还没有被审核，无法打印清单！',
                    type: 'error'
                });
                return;
            }
        },
        excelEdit3: function (rowIndex, row) {
            var _this = this;
            if (row.type == '等待确认单' || row.type == '审核通过' || row.type == '结果确认' || row.type == '待完成' || row.type == '已完成') {
                $.post("/home/purchase_orders/selectOrdersAllById",
                    {"ordersId": row.ordersid},
                    function (data) {
                        if (data.code == 200) {
                            $("#wrap-left").load("http://" + window.location.host + "/home/memorandInUnitingPring.html", function () {
                                purchaseAndOrdersdetailResultVaidation.urchaseAndOrdersdetail = data.data.purchaseOrders;
                            });
                        } else {
                            _this.$notify({
                                message: "对不起，没有查询到对应的合同信息！",
                                type: 'error'
                            });
                            return;
                        }
                    });
            } else {
                _this.$notify({
                    message: "对不起，当前订单尚不能生成对应的合同信息！",
                    type: 'error'
                });
                return;
            }
        },
        //数据组合

        dataCombination: function (queryAllData4PurchaseVoList) {
            var _this = this;
            _this.tableData3 = [];
            for (var i = 0; i < queryAllData4PurchaseVoList.length; i++) {

                for (var j = 0; j < queryAllData4PurchaseVoList[i].purchaseDetailedListList.length; j++) {
                    var map = {};
                    debugger
                    map.entryname = queryAllData4PurchaseVoList[i].entry_name;
                    map.companyname = queryAllData4PurchaseVoList[i].company_name;
                    map.goodsName = queryAllData4PurchaseVoList[i].purchaseDetailedListList[j].goodsName;
                    map.lxr = queryAllData4PurchaseVoList[i].lxr;
                    map.pmmc = queryAllData4PurchaseVoList[i].purchaseDetailedListList[j].pmmc;
                    map.ggxh = queryAllData4PurchaseVoList[i].purchaseDetailedListList[j].ggxh;
                    map.zj = queryAllData4PurchaseVoList[i].purchaseDetailedListList[j].zj;
                    map.createtime = queryAllData4PurchaseVoList[i].purchaseDetailedListList[j].createtime;
                    map.type = queryAllData4PurchaseVoList[i].purchaseDetailedListList[j].type;
                    map.ordersid = queryAllData4PurchaseVoList[i].id;
                    map.gmfs = queryAllData4PurchaseVoList[i].purchaseDetailedListList[j].gmfs;
                    map.quotationid = queryAllData4PurchaseVoList[i].purchaseDetailedListList[j].id;
                    _this.tableData3.push(map);
                }


            }
        },


    },

    //页面加载完成后执行此方法
    created: function () {
        var _this = this;

        $.post("/home/purchase_orders/queryAllDatas",
            {"cond": '待审核', "goodsName": '', "GMFS": '', "entryName": '', "contact": ''},
            function (data) {
                _this.dataCombination(data.data.queryAllData4PurchaseVoList);
            });
    },
});